package hp.com.servlet.UsersServlet;

import hp.com.entity.Orders;
import hp.com.entity.Users;
import hp.com.service.OrderService;
import hp.com.service.UsersService;
import hp.com.service.impl.OrderServiceImpl;
import hp.com.service.impl.UsersServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/User")
public class MemberUserServlet extends HttpServlet {
    private UsersService usersService = new UsersServiceImpl();
    private OrderService orderService = new OrderServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            req.setCharacterEncoding("utf-8");
            HttpSession session = req.getSession();
            //判断是否登录且获取对象
            if (session.getAttribute("userSession") == null) {
                req.getRequestDispatcher(req.getContextPath() + "/Login").forward(req, resp);
            } else {
                Users user = (Users) session.getAttribute("userSession");
                req.setAttribute("user", user);
                int fahuo = 0;
                int daishouhuo = 0;
                int shouhuo = 0;
                req.getRequestDispatcher(req.getContextPath() + "/ManageSystem/User/UserDashBoard.jsp").forward(req, resp);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
